package mya.mes.mdc.local.alarm;

import mya.common.util.Utils;
import mya.mes.mdc.model.alarm.MdcAlarm;
import mya.mes.mdc.model.dispatch.MdcDispatchContent;
import mya.mes.mdc.share.api.MdcModule;

import java.util.List;

public class MdcAlarmResult {

    public List<MdcAlarm> alarmCreatedList;
    public List<MdcAlarm> alarmCloseList;


    public MdcDispatchContent dispatchContent = null;

    public MdcAlarmResult() {
    }


    public MdcAlarmResult(List<MdcAlarm> alarmCreatedList, List<MdcAlarm> alarmCloseList) {
        this.alarmCreatedList = alarmCreatedList;
        this.alarmCloseList = alarmCloseList;
    }


    public boolean isNullOrEmpty() {
        return Utils.isNullOrEmpty(alarmCreatedList) &&
                Utils.isNullOrEmpty(alarmCloseList);
    }

    /**
     * 是否需要把报警关闭的消息发送到微信服务器
     *
     * @return
     */
    public boolean isNeedDispatchStopAlarm() {
        if(!MdcModule.getInstance().getMdcOptions().ALARM_SENT_TO_WEIXIN) {
            return  false;
        }
        if (alarmCloseList == null || alarmCloseList.isEmpty()) {
            return false;
        }
        boolean hasSent = false;
        for(MdcAlarm closed:  alarmCloseList) {
            if(Utils.valueBoolean(closed.hasSentToPerson)) {
                hasSent = true;
                break;
            }
            if(Utils.valueBoolean(closed.hasSentToManager)) {
                hasSent = true;
                break;
            }
        }
        return hasSent;
    }

}
